//
//  UpLevelViewController.m
//  PeopleStreet
//
//  Created by 刘建峰 on 16/6/30.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "UpLevelViewController.h"
#import "UpLevelCollectionViewCell.h"

static NSString * cellIndentifer = @"UpLevelCollectionViewCell";
@interface UpLevelViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UIScrollView *scroView;
@property(nonatomic,strong)NSIndexPath * currentIndexPath;
@end

@implementation UpLevelViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initViewLayout];
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroView];
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 505), NO);
    
    for (UIView * view in self.scroView.subviews) {
        if ([view isKindOfClass:[UILabel class]]) {
            UILabel * label = (UILabel *)view;
            if ([label.text isEqualToString:@"升级"]) {
                label.layer.masksToBounds = YES;
                label.layer.cornerRadius = 12*VerticalRatio();
            }
        }
    }
    
    UICollectionViewFlowLayout *flowLayout =[[UICollectionViewFlowLayout alloc]init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    flowLayout.minimumInteritemSpacing = 0*VerticalRatio();
    flowLayout.minimumLineSpacing = 0*VerticalRatio();
    self.collectionView.collectionViewLayout = flowLayout;
    self.collectionView.userInteractionEnabled=YES;
//    _collectionView.delegate = self;
//    _collectionView.dataSource = self;
    [self.collectionView registerNib:[UINib nibWithNibName:cellIndentifer bundle:nil] forCellWithReuseIdentifier:cellIndentifer];
    

}

- (IBAction)back:(id)sender {
    [self.navigationController  popViewControllerAnimated:YES];
}

#pragma mark === 立即升级
- (IBAction)upLevelNow:(id)sender {
}


#pragma mark === 升级会员等级
- (IBAction)levelUpVIP:(UIButton *)sender {
    NSInteger level = sender.tag-1000;
}



#pragma mark -- UICollectionViewDataSource
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
 
        return 4;
    
    
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
        return CGSizeMake(160*VerticalRatio(), 80*VerticalRatio());
}
//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
  
    return UIEdgeInsetsMake(0,0, 0*VerticalRatio(), 0*VerticalRatio());
    
}
//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
        UpLevelCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIndentifer forIndexPath:indexPath];
    
    return cell;
        
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
//        ShopViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"Shop"];
//        page.storeId = _brandSellingArray[indexPath.row][@"mbraId"];
//        [self.navigationController   pushViewController:page animated:YES];
    
    if (_currentIndexPath) {
        UpLevelCollectionViewCell * lastcell = (UpLevelCollectionViewCell *)[_collectionView cellForItemAtIndexPath:_currentIndexPath];
        lastcell.chosenButton.hidden = YES;
        lastcell.backLineView.layer.borderColor = [UIColor colorWithWhite:0.859 alpha:1.000].CGColor;
    }
    
    UpLevelCollectionViewCell * cell = (UpLevelCollectionViewCell *)[_collectionView cellForItemAtIndexPath:indexPath];
    cell.chosenButton.hidden = NO;
    cell.backLineView.layer.borderColor = [UIColor colorWithRed:1.000 green:0.647 blue:0.035 alpha:1.000].CGColor;
    _currentIndexPath = indexPath;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
